package FilterDesigners.Tests.Butterworth;

import FilterDesigners.Butterworth.HighpassButterworthFilter;
import junit.framework.TestCase;
import java.lang.Math;

public class HighpassButterworthFilterTest extends TestCase{

	private HighpassButterworthFilter hPBFilter;
	
	double W1 = 4000*Math.PI; 
	double W2 = 10000*Math.PI; 
	double K1 = 2; 
	double K2 = 20; 
	
	public void setUp() {
		hPBFilter = new HighpassButterworthFilter(W1, W2, K1, K2);
	}
	
	public void testCalculate3dBFreq() {
		double W1p = W2/W2;
		double W2p = W2/W1;
		double wcPrimeExpected = W1p/Math.pow(Math.pow(10.0, K1/10.0) - 1, 1.0/(2.0*hPBFilter.ORDER));
		double wc2PrimeExpected = W2p/Math.pow(Math.pow(10.0, K2/10.0) - 1, 1.0/(2.0*hPBFilter.ORDER));
		double expectedFreqPrime = Math.sqrt(wcPrimeExpected*wc2PrimeExpected);
		double expectedFreq = W2/expectedFreqPrime;
		assertEquals(expectedFreq, hPBFilter.get3dBFreq());
		assertEquals(27865, hPBFilter.get3dBFreq(), 1); // Compare to hand calculation with acceptable error of 1.0
	}
	
	public void testCalculateNormalizedComponents() {
		assertEquals(1.0/(2.0*hPBFilter.getQValues().get(0)), hPBFilter.getNormalizedComponents().get(0), 0.0000001);
		assertEquals(1.0, hPBFilter.getNormalizedComponents().get(1), 0.0000001);
		assertEquals(2.0*hPBFilter.getQValues().get(0), hPBFilter.getNormalizedComponents().get(2), 0.0000001);
		assertEquals(1.0, hPBFilter.getNormalizedComponents().get(3), 0.0000001);
	}
}
